package com.pro.service.imple;

import com.pro.mapper.JsLogMapper;
import com.pro.pojo.JsLog;
import com.pro.pojo.JsonData;
import com.pro.service.JsLogService;
import com.pro.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 祖铭泽
 * @Date 2022/1/14/0014
 * @description 日志 业务层 实现类
 */
@Service
public class JsLogServiceImple implements JsLogService {
    @Autowired
    private JsLogMapper jsLogMapper;
    /**
     * @Author 祖铭泽
     * @Date 2022/1/14/0014
     * @description 添加日志
     */
    @Override
    public JsonData addLog(JsLog jsLog) {
        jsLog.setCreateDate(DateUtils.tranferDateTimeToString(new Date()));
        boolean addLog = jsLogMapper.addLog(jsLog);
        return addLog ? JsonData.buildSuccess(jsLog) : JsonData.buildError("添加失败");
    }
    /**
     * @Author 祖铭泽
     * @Date 2022/1/14/0014
     * @description 根据分类类型、分类备注、操作时间、创建人查询日志
     */
    @Override
    public JsonData getCourseLogs(JsLog jsLog) {
        jsLog.setLogType(2);
        List<JsLog> courseLogs = jsLogMapper.getCourseLogs(jsLog);
        return courseLogs != null ? JsonData.buildSuccess(courseLogs) : JsonData.buildError("查询失败");
    }
    /**
     * @Author 祖铭泽
     * @Date 2022/1/14/0014
     * @description 根据日志id删除日志
     */
    @Override
    public JsonData deleteLog(Integer logId) {
        boolean deleteLog = jsLogMapper.deleteLog(logId);
        return deleteLog ? JsonData.buildSuccess(deleteLog) : JsonData.buildError("删除失败");
    }
}
